<template>
  <div>
    <van-nav-bar
        :title="comment.reply_count?comment.reply_count+'条评论' :'暂无回复'"
    >
      <template #left>
        <van-icon name="cross" @click="$emit('back')"/>
      </template>
    </van-nav-bar>
    <div class="sroll-center">
      <CommentItem :row="comment"></CommentItem>
      <van-cell title="全部回复"/>
      <CommentList type="c" :list="list" :source="comment.com_id"></CommentList>
    </div>
    <div class="post-warp">
      <van-button round @click="isShowReply=true">评论</van-button>
    </div>
    <van-popup v-model="isShowReply" position="bottom">
      <CommentPost :target="comment.com_id"
                   :art_id="$route.params.articleId"
                   @updatecomment="onPostSuccess"></CommentPost>
    </van-popup>
  </div>
</template>

<script>
import CommentItem from '@/components/CommentItem'
import CommentList from '@/components/CommentList'
import CommentPost from '@/views/Article/components/commentPost'

export default {
  name: 'CommentReply',
  components: {
    CommentItem,
    CommentList,
    CommentPost
  },
  data () {
    return {
      list: [],
      isShowReply: false
    }
  },
  props: {
    comment: {
      type: Object,
      required: true
    }
  },
  methods: {
    onPostSuccess (data) {
      this.list.push(data)
      this.isShowReply = false
      this.comment.reply_count++
    }
  }
}
</script>

<style scoped lang='less'>
.post-warp {
  width: 100%;
  height: 100px;
  position: fixed;
  bottom: 0;
  border-top: 1px solid #ccc;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #ccc;

  .van-button {
    width: 640px;
    height: 80px;
  }
}

.sroll-center {
  position: absolute;
  top: 92px;
  bottom: 100px;
  width: 100%;
  overflow-y: scroll;
}
</style>
